package com.zb.dao.ext.base;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.stereotype.Repository;

import com.zb.dao.base.OmsCommonDao;
import com.zb.entity.exception.OmsDaoException;

/**
 *系统上传文件操作的类
 * 
 * @author huanghao
 * 
 */
@Repository
public class OmsStoreFileDao<OmsStoreFile> extends OmsCommonDao<OmsStoreFile>
{

	public void updateStoreFileWithIds(final String entityId,final String entityTbl,final String[] storeIds) throws OmsDaoException
	{
		StringBuilder updateStoreFileSql = new StringBuilder( "update oms_store_file set entity_id = ? where entity_tbl = ? and file_id in (");
		
		for (int i = 0;i < storeIds.length;i++ )
		{
			if (i > 0)
			{
				updateStoreFileSql.append(",");
			}
			updateStoreFileSql.append("?");
		}
		updateStoreFileSql.append(")");
		try
		{
			this.getJdbcTemplate().update(updateStoreFileSql.toString(),new PreparedStatementSetter() 
			{
				
				@Override
				public void setValues(PreparedStatement arg0) throws SQLException 
				{
					int index = 1;
					arg0.setString(index++, entityId);
					arg0.setString(index++, entityTbl);
					for (String storeId : storeIds)
					{
						arg0.setString(index++, storeId);
					}
				}
			});
		}
		catch(Exception e)
		{
			throw new OmsDaoException(e);
		}
		
	}
} 
